package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.GlideUtil;
import com.a3dweijing.wetouch2.Util.ImageLoaderUtil;
import com.a3dweijing.wetouch2.bean.VideoType;
import com.a3dweijing.wetouch2.callback.PartitionOnclick;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by Yxd on 2017/10/31.
 */

public class PartitionTopRecAdapter extends RecyclerView.Adapter<PartitionTopRecAdapter.MyViewHolder> {
    private Context context;
    private List<VideoType> types;
    private PartitionOnclick onclick;

    public PartitionTopRecAdapter(Context context, List<VideoType> types, PartitionOnclick onclick) {
        this.context = context;
        this.types = types;
        this.onclick=onclick;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_partition_top,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
//        ImageLoaderUtil.getLoader().loadImg(types.get(position).getWc_type_img(),holder.img);
        GlideUtil.getInstance().showImage(context,"https://lfriend.oss-cn-shenzhen.aliyuncs.com/"+types.get(position).getWc_type_img(),holder.img);
        holder.tv.setText(types.get(position).getWc_type_name());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onclick!=null){
                    onclick.typeclick(position,types.get(position));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return types.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView tv;
        public MyViewHolder(View itemView) {
            super(itemView);
            img= (ImageView) itemView.findViewById(R.id.video_type_pic);
            tv= (TextView) itemView.findViewById(R.id.video_type_name);
        }
    }
}
